package be.xios.ti.droodle;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

/**
 * Een JPanel dat een Drawing kan weergeven
 * 
 * @author Kris Hermans
 */
@SuppressWarnings("serial")
public class ShapeJPanel extends JPanel {
	
	private JLabel statusLabel;
	private JComboBox sizeBox;
	private Drawing drawing;
	private ShapeDrawAction currentAction;
	
	
	public ShapeJPanel(JLabel l, JComboBox sizeBox) {
		super();
		drawing = new Drawing();
		currentAction = null;
		
		this.sizeBox = sizeBox;
		
		this.statusLabel = l;
		setOpaque(true);
		setBackground(Color.WHITE);
		addMouseMotionListener(new MouseMotionAdapter() {
			public void mouseMoved(MouseEvent e) {
				statusLabel.setText("["+e.getX()+","+e.getY()+"]");
			}
		});
		addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				if (currentAction != null) {
					currentAction.click(e);
				}
			}
		});
	}
	public void paint(Graphics g) {
		super.paint(g);
        setBackground(drawing.getBackground());
		drawing.draw(g);
	}
	/**
	 * @param currentAction The currentAction to set.
	 */
	public void setCurrentAction(ShapeDrawAction currentAction) {
		this.currentAction = currentAction;
	}
	/**
	 * @return Returns the drawing.
	 */
	public Drawing getDrawing() {
		return drawing;
	}
	
	
	/**
	 * @param drawing The drawing to set.
	 */
	public void setDrawing(Drawing drawing) {
		this.drawing = drawing;
		this.repaint();
	}
	
	/* (non-Javadoc)
	 * @see java.awt.Component#setBackground(java.awt.Color)
	 */
	public void setBackground(Color bg) {
		super.setBackground(bg);
		if (drawing != null)
			drawing.setBackground(bg);
	}
	
	public int getPenSize() {
		return sizeBox.getSelectedIndex()+1;
	}
}
